package com.hekang.fragmentdemo;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by hekang on 2018/9/9.
 */

public class FragmentValues3 extends Fragment implements View.OnClickListener{
    private IButton iButton;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragmnet3, container, false);
        //初始化控件
        Button button1 = view.findViewById(R.id.but1);
        Button button2 = view.findViewById(R.id.but2);
        Button button3 = view.findViewById(R.id.but3);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        return view;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        try {
            iButton = (IButton)context;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View v) {
        iButton.onFragmentBtnClick(((Button)v).getText().toString());
    }
}
